package com.qzsf.backend.mapper.sql;

import org.apache.ibatis.jdbc.SQL;

/*
 * @Author: Dennis Chen
 * @CreateTime: 2024/11/25 15:14 周一
 * @Email 1429278462@qq.com
 * @Remark 参与情况多条件查询
 * @Version 1.0
 */
public class ParticipationSqlProvider {
    public String getParticipationByCondition(String userName,String eventName) {
        return new SQL() {{
            SELECT("a.id,c.name as userName,b.name as eventName,a.hours,a.created_at as createdAt");
            FROM("participation a");
            LEFT_OUTER_JOIN("event b ON a.event_id = b.id");
            LEFT_OUTER_JOIN("user_profile c on a.user_id = c.id");

            if (userName != null) {
                WHERE("c.name LIKE CONCAT('%', #{userName}, '%')");
            }

            if (eventName != null) {
                WHERE("b.name LIKE CONCAT('%', #{eventName}, '%')");
            }
        }}.toString();
    }
}
